﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Jemgine.MapEditor
{
	public partial class OperationList : UserControl
	{
		EditorState EditorState;

		internal void SetEditorState(EditorState ES)
		{
			EditorState = ES;
            ES.OnOperationStackChange += RebuildOperationList;
		}

		public OperationList()
		{
			InitializeComponent();
		}

        internal void RebuildOperationList(List<Operation> Operations)
        {
            _listBox.Items.Clear();

            foreach (Operation Operation in Operations)
                _listBox.Items.Insert(0, Operation.GetType().Name);

            Invalidate();
        }

        private void clearButton_Click(object sender, EventArgs e)
        {
            var MboxResult = MessageBox.Show("Are you sure you want to clear the undo history?", "", MessageBoxButtons.YesNo);
            if (MboxResult == DialogResult.Yes)
                EditorState.ClearUndoList();
            Invalidate();
        }

		
	}
}
